<!--
 * @Author: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @Date: 2022-08-27 08:36:18
 * @LastEditors: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @LastEditTime: 2022-08-27 09:56:49
 * @FilePath: \后端管理系统\app\src\views\Orders\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <MyBreadcrumb :breadList="$route.meta.breadList" />

    <el-table :data="tableData" border style="width: 100%" class="table">
      <el-table-column type="index" width="50"> </el-table-column>
      <el-table-column prop="order_number" label="订单编号"> </el-table-column>
      <el-table-column prop="order_price" label="订单价格"> </el-table-column>
      <el-table-column prop="order_pay" label="是否付款">
        <template v-slot="scope">
          <el-tag v-if="scope.row.order_pay == 0" type="danger">未付款</el-tag>
          <el-tag v-else-if="scope.row.order_pay == 1" type="success"
            >已付款</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column label="是否发货" prop="is_send"></el-table-column>
      <el-table-column prop="create_time" label="下单时间">
        <template v-slot="scope">
          {{ scope.row.create_time | newdata }}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small"
            >查看</el-button
          >
          <el-button type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="obj.pagenum"
      :page-sizes="[5, 10, 15, 20, 25]"
      :page-size="obj.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import MyBreadcrumb from "../../components/MyBreadcrumb.vue";
import { httpOrders } from "../../api/orders";
export default {
  components: {
    MyBreadcrumb,
  },
  data() {
    return {
      obj: {
        query: "",
        pagenum: 1,
        pagesize: 5,
      },
      tableData: [],
      total: 0,
    };
  },
  created() {
    this.initOrders();
  },
  methods: {
    async initOrders() {
      const res = await httpOrders("orders", this.obj);
      console.log(res);
      this.tableData = res.data.data.goods;
      this.total = res.data.data.total;
    },
    handleSizeChange(val) {
      this.obj.pagesize = val;
      this.initOrders();
    },
    handleCurrentChange(val) {
      this.obj.pagenum = val;
      this.initOrders();
    },
  },
};
</script>

<style>
.table {
  margin-top: 20px;
}
</style>